package convert;

import org.springframework.core.convert.converter.Converter;

import java.text.SimpleDateFormat;
import java.util.Date;

//泛型前者指的是传入类型，后者是传出类型
public class SimpleDateConvert implements Converter<String, Date> {
    @Override
    public Date convert(String s) {

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date;
        try {
            String strDate = format.format((Long.valueOf(s)));
            date = format.parse(strDate);
        } catch (Exception ex) {
            date = new Date();
        }

        return date;
    }
}
